<?php
/**
 * 用户
 *
 *
 */


class orderdetail_model extends CI_Model
{
	const tableName = "orderdetail";
	
	var $serialNumber;

	var $type;

	var $restaurantId;
	
	var $userId;

	var $totalPrice;
	
	var $status;

	var $memo;
	
	var $deliverAddress;

	var $deliverPhone;
	
	var $deliverPhone2;

	var $deliverTime;
	
	var $deliverAddressId;

	function __construct()
	{
		parent::__construct();
	}
	
	/**
	 *
	 * 插入user数据
	 */
	function insert_orderdetail($data)
	{
		$this->serialNumber = isset($data['serialNumber'])?$data['serialNumber'] : null;
		$this->type =  isset($data['type'])?$data['type'] : null;
		$this->restaurantId =  isset($data['restaurantId'])?$data['restaurantId'] : null;
		$this->userId =  isset($data['userId'])?$data['userId'] : null;	
		$this->totalPrice =  isset($data['totalPrice'])?$data['totalPrice'] : null;
		$this->status =  isset($data['status'])?$data['status'] : null;	
		$this->memo =  isset($data['memo'])?$data['memo'] : null;
		
		//TODO deliverName
		$this->deliverName =  isset($data['deliverName'])?$data['deliverName'] : null;	
		$this->deliverAddress =  isset($data['deliverAddress'])?$data['deliverAddress'] : null;	
		$this->deliverPhone =  isset($data['deliverPhone'])?$data['deliverPhone'] : null;
		$this->deliverPhone2 =  isset($data['deliverPhone2'])?$data['deliverPhone2'] : null;	
		$this->deliverTime =  isset($data['deliverTime'])?$data['deliverTime'] : null;		
		$this->deliverAddressId =  isset($data['deliverAddressId'])?$data['deliverAddressId'] : 1;
		
		$this->db->insert(self::tableName, $this);
	}
	

	
	function getOrderdetailByUserid($userid){
		$query = $this->db->query("select * from ".self::tableName." where userid = {$userid}");
		return $query->result();
	}
	
	function getOrderdetailByIdarray($idArray)
	{
		if(count($idArray)<=0)
		{
			return array();
		}
		$idStr = implode(',', $idArray);
		$idStr = substr($idStr, 2);
		$query = $this->db->query("select * from ".self::tableName." where id in ({$idStr})");
		//$query = $this->db->query("select * from ".self::tableName." where resutaurantId = ".$restaurantid);
		return $query->result() ;
		
	}
}